import 'package:flutter_im_demo/model/add_friend_message_model.dart';
import 'package:flutter_im_demo/model/message_model.dart';
import 'package:flutter_im_demo/state/global_state.dart';
import 'package:provider/provider.dart';
import 'package:flutter/material.dart';

import '../const_value.dart';
import 'friend_list_page.dart';

class AddFriendListPage extends StatefulWidget {
  @override
  _AddFriendListPageState createState() => _AddFriendListPageState();
}

class _AddFriendListPageState extends State<AddFriendListPage> {
  Future<List<AddFriendMessageModel>> messageList;

  @override
  void initState() {
    super.initState();
    messageList = GlobalState.queryAddFriendMessage();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("新的朋友"),
        flexibleSpace: Container(
          decoration: BoxDecoration(gradient: gradientColor),
        ),
      ),
      body: FutureBuilder<List<AddFriendMessageModel>>(
          builder: (context, futureData) {
            if (futureData.hasData) {
              final list = futureData.data;
              return ListView.builder(
                itemBuilder: (c, index) {
                  final msgItem = list[index];
                  return ListTile(
                    onTap: () {},
                    leading: MyCircleAvatar(
                        height: 40.0,
                        avatar: msgItem.avatar,
                        tag: msgItem.friendId),
                    title: Text(
                      msgItem.nickName,
                      style: TextStyle(
                          fontWeight: FontWeight.bold, fontSize: 16.0),
                    ),
                    subtitle: Text(msgItem.body),
                    trailing: FlatButton(onPressed: () {}, child: Text("同意")),
                  );
                },
                itemCount: list.length,
              );
            } else {
              return Center(
                child: Text("Loading ..."),
              );
            }
          },
          future: messageList),
    );
  }
}
